#pragma once
#include <iostream>
#include "Protocol.hpp"

class Cal{
public:
	Response Execute(Request & req){
		Response res;
		int x = req.X();
		int y = req.Y();
		char op = req.Op();

		switch(op){
			case '+':
				res.SetResult(x + y);
				res.SetCode(0);
				break;
			case '-':
				res.SetResult(x - y);
				res.SetCode(0);
				break;
			case '*':
				res.SetResult(x * y);
				res.SetCode(0);
				break;
			case '/':
				// 除0错误
				if(y == 0){
					res.SetCode(1);
					break;
				}
			
				res.SetResult(x / y);
				res.SetCode(0);
				break;
			case '%':
				// 模0错误
				if(y == 0){
					res.SetCode(2);
					break;
				}
			
				res.SetResult(x % y);
				res.SetCode(0);
				break;
			default:
				// 操作符错误
				res.SetCode(3);
				break;
		}

		return res;
	}

private:

};